function[Dst,fday] = read_dst_file(filename),

%Read Dst values from FORMATTED files available at 
% Dst index:The Dst index file is a WDC format ASCII file composed of one logical
%    1000 FORMAT(3X,2I2,1X,I2,10X,24I4)
% *
% *        where:
% *
% *        Name                 Type              Description                         
% *        ----                 ----              -----------                         
% *                                                                               
% *        YEAR                 Int   Year since 1900.
% *
% *        MONTH                Int   Month of year.
% *
% *        DAY                  Int   Day of month.
% *
% *        JDST(24)             Int   Hourly means of Dst magnetic index values
% *                                   (nT) for this day such that JDST(i) is mean
% *                                   value over (i-1)th hour, thus values are
% *                                   centered on the half-hour.
% *
% *        These files types may be retrieved in one-year segments from:
% *
% *             ftp://ftp.ngdc.noaa.gov/STP/GEOMAGNETIC_DATA/INDICES/DST/
% *
% *        as:
% *
% *             dstXXXX

flag =1;
k = 1;
fid = fopen(filename,'rt');
while (flag == 1),
S = fgetl(fid);

if (S == -1) 
    flag = 0; 
    break; 
end;
iy(k) = sscanf(S(4:5),'%d');
im(k) = sscanf(S(6:7),'%d');
id(k) = sscanf(S(9:10),'%d');
Dst(:,k) = sscanf(S(15:end),'%d');
k=k+1;
end;

fday = datenum(iy,im,id) - datenum(2000,1,1);
